package com.rlyy.grpc.lib;

import static io.grpc.MethodDescriptor.generateFullMethodName;
import static io.grpc.stub.ClientCalls.asyncUnaryCall;
import static io.grpc.stub.ClientCalls.blockingUnaryCall;
import static io.grpc.stub.ClientCalls.futureUnaryCall;
import static io.grpc.stub.ServerCalls.asyncUnaryCall;
import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;

/**
 */
@javax.annotation.Generated(
    value = "by gRPC proto compiler (version 1.33.1)",
    comments = "Source: handler.proto")
public final class GrpcInterfaceGrpc {

  private GrpcInterfaceGrpc() {}

  public static final String SERVICE_NAME = "grpc.GrpcInterface";

  // Static method descriptors that strictly reflect the proto.
  private static volatile io.grpc.MethodDescriptor<RequestMessage,
      ResponseMessage> getHandlerMethod;

  @io.grpc.stub.annotations.RpcMethod(
      fullMethodName = SERVICE_NAME + '/' + "handler",
      requestType = RequestMessage.class,
      responseType = ResponseMessage.class,
      methodType = io.grpc.MethodDescriptor.MethodType.UNARY)
  public static io.grpc.MethodDescriptor<RequestMessage,
      ResponseMessage> getHandlerMethod() {
    io.grpc.MethodDescriptor<RequestMessage, ResponseMessage> getHandlerMethod;
    if ((getHandlerMethod = GrpcInterfaceGrpc.getHandlerMethod) == null) {
      synchronized (GrpcInterfaceGrpc.class) {
        if ((getHandlerMethod = GrpcInterfaceGrpc.getHandlerMethod) == null) {
          GrpcInterfaceGrpc.getHandlerMethod = getHandlerMethod =
              io.grpc.MethodDescriptor.<RequestMessage, ResponseMessage>newBuilder()
              .setType(io.grpc.MethodDescriptor.MethodType.UNARY)
              .setFullMethodName(generateFullMethodName(SERVICE_NAME, "handler"))
              .setSampledToLocalTracing(true)
              .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
                  RequestMessage.getDefaultInstance()))
              .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
                  ResponseMessage.getDefaultInstance()))
              .setSchemaDescriptor(new GrpcInterfaceMethodDescriptorSupplier("handler"))
              .build();
        }
      }
    }
    return getHandlerMethod;
  }

  /**
   * Creates a new async stub that supports all call types for the service
   */
  public static GrpcInterfaceStub newStub(io.grpc.Channel channel) {
    io.grpc.stub.AbstractStub.StubFactory<GrpcInterfaceStub> factory =
      new io.grpc.stub.AbstractStub.StubFactory<GrpcInterfaceStub>() {
        @Override
        public GrpcInterfaceStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
          return new GrpcInterfaceStub(channel, callOptions);
        }
      };
    return GrpcInterfaceStub.newStub(factory, channel);
  }

  /**
   * Creates a new blocking-style stub that supports unary and streaming output calls on the service
   */
  public static GrpcInterfaceBlockingStub newBlockingStub(
      io.grpc.Channel channel) {
    io.grpc.stub.AbstractStub.StubFactory<GrpcInterfaceBlockingStub> factory =
      new io.grpc.stub.AbstractStub.StubFactory<GrpcInterfaceBlockingStub>() {
        @Override
        public GrpcInterfaceBlockingStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
          return new GrpcInterfaceBlockingStub(channel, callOptions);
        }
      };
    return GrpcInterfaceBlockingStub.newStub(factory, channel);
  }

  /**
   * Creates a new ListenableFuture-style stub that supports unary calls on the service
   */
  public static GrpcInterfaceFutureStub newFutureStub(
      io.grpc.Channel channel) {
    io.grpc.stub.AbstractStub.StubFactory<GrpcInterfaceFutureStub> factory =
      new io.grpc.stub.AbstractStub.StubFactory<GrpcInterfaceFutureStub>() {
        @Override
        public GrpcInterfaceFutureStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
          return new GrpcInterfaceFutureStub(channel, callOptions);
        }
      };
    return GrpcInterfaceFutureStub.newStub(factory, channel);
  }

  /**
   */
  public static abstract class GrpcInterfaceImplBase implements io.grpc.BindableService {

    /**
     */
    public void handler(RequestMessage request,
                        io.grpc.stub.StreamObserver<ResponseMessage> responseObserver) {
      asyncUnimplementedUnaryCall(getHandlerMethod(), responseObserver);
    }

    @Override public final io.grpc.ServerServiceDefinition bindService() {
      return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
          .addMethod(
            getHandlerMethod(),
            asyncUnaryCall(
              new MethodHandlers<
                RequestMessage,
                ResponseMessage>(
                  this, METHODID_HANDLER)))
          .build();
    }
  }

  /**
   */
  public static final class GrpcInterfaceStub extends io.grpc.stub.AbstractAsyncStub<GrpcInterfaceStub> {
    private GrpcInterfaceStub(
        io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
      super(channel, callOptions);
    }

    @Override
    protected GrpcInterfaceStub build(
        io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
      return new GrpcInterfaceStub(channel, callOptions);
    }

    /**
     */
    public void handler(RequestMessage request,
                        io.grpc.stub.StreamObserver<ResponseMessage> responseObserver) {
      asyncUnaryCall(
          getChannel().newCall(getHandlerMethod(), getCallOptions()), request, responseObserver);
    }
  }

  /**
   */
  public static final class GrpcInterfaceBlockingStub extends io.grpc.stub.AbstractBlockingStub<GrpcInterfaceBlockingStub> {
    private GrpcInterfaceBlockingStub(
        io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
      super(channel, callOptions);
    }

    @Override
    protected GrpcInterfaceBlockingStub build(
        io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
      return new GrpcInterfaceBlockingStub(channel, callOptions);
    }

    /**
     */
    public ResponseMessage handler(RequestMessage request) {
      return blockingUnaryCall(
          getChannel(), getHandlerMethod(), getCallOptions(), request);
    }
  }

  /**
   */
  public static final class GrpcInterfaceFutureStub extends io.grpc.stub.AbstractFutureStub<GrpcInterfaceFutureStub> {
    private GrpcInterfaceFutureStub(
        io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
      super(channel, callOptions);
    }

    @Override
    protected GrpcInterfaceFutureStub build(
        io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
      return new GrpcInterfaceFutureStub(channel, callOptions);
    }

    /**
     */
    public com.google.common.util.concurrent.ListenableFuture<ResponseMessage> handler(
        RequestMessage request) {
      return futureUnaryCall(
          getChannel().newCall(getHandlerMethod(), getCallOptions()), request);
    }
  }

  private static final int METHODID_HANDLER = 0;

  private static final class MethodHandlers<Req, Resp> implements
      io.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,
      io.grpc.stub.ServerCalls.ServerStreamingMethod<Req, Resp>,
      io.grpc.stub.ServerCalls.ClientStreamingMethod<Req, Resp>,
      io.grpc.stub.ServerCalls.BidiStreamingMethod<Req, Resp> {
    private final GrpcInterfaceImplBase serviceImpl;
    private final int methodId;

    MethodHandlers(GrpcInterfaceImplBase serviceImpl, int methodId) {
      this.serviceImpl = serviceImpl;
      this.methodId = methodId;
    }

    @Override
    @SuppressWarnings("unchecked")
    public void invoke(Req request, io.grpc.stub.StreamObserver<Resp> responseObserver) {
      switch (methodId) {
        case METHODID_HANDLER:
          serviceImpl.handler((RequestMessage) request,
              (io.grpc.stub.StreamObserver<ResponseMessage>) responseObserver);
          break;
        default:
          throw new AssertionError();
      }
    }

    @Override
    @SuppressWarnings("unchecked")
    public io.grpc.stub.StreamObserver<Req> invoke(
        io.grpc.stub.StreamObserver<Resp> responseObserver) {
      switch (methodId) {
        default:
          throw new AssertionError();
      }
    }
  }

  private static abstract class GrpcInterfaceBaseDescriptorSupplier
      implements io.grpc.protobuf.ProtoFileDescriptorSupplier, io.grpc.protobuf.ProtoServiceDescriptorSupplier {
    GrpcInterfaceBaseDescriptorSupplier() {}

    @Override
    public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() {
      return GrpcHandler.getDescriptor();
    }

    @Override
    public com.google.protobuf.Descriptors.ServiceDescriptor getServiceDescriptor() {
      return getFileDescriptor().findServiceByName("GrpcInterface");
    }
  }

  private static final class GrpcInterfaceFileDescriptorSupplier
      extends GrpcInterfaceBaseDescriptorSupplier {
    GrpcInterfaceFileDescriptorSupplier() {}
  }

  private static final class GrpcInterfaceMethodDescriptorSupplier
      extends GrpcInterfaceBaseDescriptorSupplier
      implements io.grpc.protobuf.ProtoMethodDescriptorSupplier {
    private final String methodName;

    GrpcInterfaceMethodDescriptorSupplier(String methodName) {
      this.methodName = methodName;
    }

    @Override
    public com.google.protobuf.Descriptors.MethodDescriptor getMethodDescriptor() {
      return getServiceDescriptor().findMethodByName(methodName);
    }
  }

  private static volatile io.grpc.ServiceDescriptor serviceDescriptor;

  public static io.grpc.ServiceDescriptor getServiceDescriptor() {
    io.grpc.ServiceDescriptor result = serviceDescriptor;
    if (result == null) {
      synchronized (GrpcInterfaceGrpc.class) {
        result = serviceDescriptor;
        if (result == null) {
          serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME)
              .setSchemaDescriptor(new GrpcInterfaceFileDescriptorSupplier())
              .addMethod(getHandlerMethod())
              .build();
        }
      }
    }
    return result;
  }
}
